package com.levy.dao.impl;

import org.nutz.dao.ConnCallback;
import org.nutz.dao.impl.DaoRunner;
import org.springframework.jdbc.datasource.DataSourceUtils;

import javax.sql.DataSource;
import java.sql.Connection;


/**
 * <pre>
 * -------------History------------------
 * DATE        AUTHOR    VERSION        DESCRIPTION
 * 2013-09-16   陈美燕                  V13.00.001      新增
 * @author <a href="chenmeiyan@asiainfo.com">陈美燕</a>
 */
public class SpringDaoRunner implements DaoRunner {

    public void run(DataSource dataSource, ConnCallback callback) {
        Connection con = DataSourceUtils.getConnection(dataSource);
        try {
            callback.invoke(con);
        }
        catch (Exception e) {
            if (e instanceof RuntimeException)
                throw (RuntimeException) e;
            else
                throw new RuntimeException(e);
        } finally {
            DataSourceUtils.releaseConnection(con, dataSource);
        }
    }
}
